From ca9145c18c8d36f899fa06ef84db003390589f01 Mon Sep 17 00:00:00 2001 From: Mike Boutin Date: Sat, 1 Aug 2015 21:09:52 -0400 Subject: [PATCH] Check for TermInfo availability to see if color output is possible before attempting to create a colored terminal. --- src/cargo/core/shell.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index 227261c8c..413c9aa08 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -144,18 +144,22 @@ impl MultiShell { impl Shell { pub fn create(out: Box, config: ShellConfig) -> Shell { - // Check for cfg!(windows) as colored output on Windows can only be supported when a tty is - // present. - if !cfg!(windows) || config.tty { - let term = TerminfoTerminal::new(out); - term.map(|t| Shell { - terminal: Colored(Box::new(t)), - config: config - }).unwrap_or_else(|| { + match ::term::terminfo::TermInfo::from_env() { + Ok(ti) => { + // Color output is possible. + Shell { + terminal: Colored(Box::new(TerminfoTerminal::new_with_terminfo(out, ti))), + config: config + } + } + _ if config.tty => { + // Color output is expected but not available, fall back to stderr. Shell { terminal: NoColor(Box::new(io::stderr())), config: config } - }) - } else { - Shell { terminal: NoColor(out), config: config } + } + _ => { + // No color output. + Shell { terminal: NoColor(out), config: config } + } } } -- 2.30.2